package operations;

import book.BookList;

import java.util.Scanner;

public class DelOperation implements IOperation{
    @Override
    public void work(BookList books) {
        System.out.println("请输入要删除的书的名称");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int i=0;
        while (i<books.getUsedSize()){
            if(books.getbook(i).getName().equals(name)){
                break;
            }
            else {
                i++;
            }
        }
        while (i< books.getUsedSize()-1){
            books.setBooks(i,books.getbook(i+1));
        }
        books.setBooks(books.getUsedSize(), null);
        books.setUsedSize(books.getUsedSize()-1);
        System.out.println("删除成功");
    }
}
